"""
LoRa模块参数定义

包含所有与LoRa模块相关的参数、选项和说明
"""

# 扩频因子(SF)与数据速率对照表
SPREADING_FACTORS = [
    {"value": 0, "name": "SF12", "description": "扩频因子12 (最远距离，最低速率)"},
    {"value": 1, "name": "SF11", "description": "扩频因子11"},
    {"value": 2, "name": "SF10", "description": "扩频因子10"},
    {"value": 3, "name": "SF9", "description": "扩频因子9"},
    {"value": 4, "name": "SF8", "description": "扩频因子8"},
    {"value": 5, "name": "SF7", "description": "扩频因子7"},
    {"value": 6, "name": "SF6", "description": "扩频因子6"},
    {"value": 7, "name": "SF5", "description": "扩频因子5 (最近距离，最高速率)"}
]

# 带宽选项
BANDWIDTH_OPTIONS = [
    {"value": 0, "name": "125 KHz", "description": "带宽 125 KHz"},
    {"value": 1, "name": "250 KHz", "description": "带宽 250 KHz"},
    {"value": 2, "name": "500 KHz", "description": "带宽 500 KHz"},
    {"value": 3, "name": "62.5 KHz", "description": "带宽 62.5 KHz"},
    {"value": 4, "name": "41.67 KHz", "description": "带宽 41.67 KHz"},
    {"value": 5, "name": "31.25 KHz", "description": "带宽 31.25 KHz"},
    {"value": 6, "name": "20.83 KHz", "description": "带宽 20.83 KHz"},
    {"value": 7, "name": "15.63 KHz", "description": "带宽 15.63 KHz"},
    {"value": 8, "name": "10.42 KHz", "description": "带宽 10.42 KHz"},
    {"value": 9, "name": "7.81 KHz", "description": "带宽 7.81 KHz"}
]

# 编码率选项
CODE_RATE_OPTIONS = [
    {"value": 1, "name": "4/5", "description": "编码率 4/5"},
    {"value": 2, "name": "4/6", "description": "编码率 4/6"},
    {"value": 3, "name": "4/7", "description": "编码率 4/7"},
    {"value": 4, "name": "4/8", "description": "编码率 4/8"}
]

# IQ转换选项
IQ_CONVERTED_OPTIONS = [
    {"value": 0, "name": "关闭", "description": "IQ转换功能关闭"},
    {"value": 1, "name": "开启", "description": "IQ转换功能开启"}
]

# 睡眠模式选项
SLEEP_MODE_OPTIONS = [
    {"value": 0, "name": "热启动", "description": "热启动模式 (保留配置)"},
    {"value": 1, "name": "冷启动", "description": "冷启动模式 (不保留配置)"}
]

# 常用频率预设(Hz)
FREQUENCY_PRESETS = [
    {"value": 433000000, "name": "433 MHz", "description": "433 MHz 频段 (欧洲常用)"},
    {"value": 470000000, "name": "470 MHz", "description": "470 MHz 频段 (中国常用)"},
    {"value": 868000000, "name": "868 MHz", "description": "868 MHz 频段 (欧洲常用)"},
    {"value": 915000000, "name": "915 MHz", "description": "915 MHz 频段 (美国常用)"}
]

# 默认配置
DEFAULT_CONFIG = {
    "frequency": 470500000,  # 470.5 MHz
    "data_rate": 5,          # SF7
    "bandwidth": 0,          # 125 KHz
    "code_rate": 1,          # 4/5
    "power": 21,             # 最大功率
    "iq_converted": 1,       # 开启IQ转换
    "local_address": 11,      # 默认本地地址
    "target_address": 12      # 默认目标地址
}

# 功率范围
POWER_RANGE = {
    "min": 0,
    "max": 22
}

# 地址范围(16位无符号整数)
ADDRESS_RANGE = {
    "min": 0,
    "max": 65535
}

# 常用波特率
BAUDRATE_OPTIONS = [
    9600,
    19200,
    38400,
    57600,
    115200,
    921600
]

# 默认串口配置
DEFAULT_SERIAL_CONFIG = {
    "baudrate": 9600,
    "timeout": 1
} 